<!--职务管理-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'module:role:save'" type="primary" @click="addOrUpdateHandle()">新增职务</el-button>
				<el-button v-auth="'module:role:delete'" type="danger" @click="deleteBatchHandle()">批量删除</el-button>
			</el-form-item>

			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>

		<el-table v-loading="state.dataListLoading" :data="state.dataList" style="width: 100%" border @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50" v-if="false"></el-table-column>

			<el-table-column width="200" prop="name" label="职务名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="description" label="职务描述" header-align="center" align="center"></el-table-column>
			<el-table-column prop="pid" label="父id" header-align="center" align="center" v-if="false"></el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'module:position/type:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
					<el-button v-auth="'module:position/type:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update :dict-type-id="dictTypeId" ref="addOrUpdateRef" @refreshDataList="getDataList"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="ModulePositionTypeIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'

import AddOrUpdate from '@/views/nb/dictionaries/data_update.vue'

import { findByCode } from '@/api/nb/business/dictionaries'

const state: IHooksOptions = reactive({
	dataListUrl: 'nb/business/dictionaries_subset/ZhiWu',
	deleteUrl: '/nb/position_type/delete',
	queryForm: {}
})

const dictTypeId = ref()

//新增页面
const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
	// addOrUpdateRef.value.pid = dictTypeId
}

//处理pid
const fnPid = (code: string) => {
	return findByCode(code).then(res => {
		dictTypeId.value = res.data.id
	})
}

fnPid('ZhiWu')
const { getDataList, deleteBatchHandle, currentChangeHandle, sizeChangeHandle, selectionChangeHandle } = useCrud(state)
</script>
